package com.itboye.eweilisten.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.itboye.eweilisten.R;
import com.itboye.eweilisten.model.SchoolBean;
import com.itboye.eweilisten.util.widget.TimeFormat;

/**
 * Created by itboye on 2017/3/11.
 */

public class ChengJiAdapter extends BaseAdapter {

    Context context;
    SchoolBean bean;
    int num;

    public ChengJiAdapter(Context context,SchoolBean bean) {
        this.context = context;
        this.bean=bean;
    }

    @Override
    public int getCount() {

        Log.d("imgStings",bean.getList().size()+"");
          return bean.getList().size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHouder houder;
        if(convertView==null){
            houder=new ViewHouder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_chengji, null);
            houder.tvScollTime= (TextView) convertView.findViewById(R.id.tvScollTime);
            houder.tvScollCount= (TextView) convertView.findViewById(R.id.tvScollCount);
            houder.tvScollYes= (TextView) convertView.findViewById(R.id.tvScollYes);
            houder.tvScollWrong= (TextView) convertView.findViewById(R.id.tvScollWrong);
            houder.tvScollLeak= (TextView) convertView.findViewById(R.id.tvScollLeak);
            houder.tvScollData= (TextView) convertView.findViewById(R.id.tvScollData);
            convertView.setTag(houder);
        }else{
            houder= (ViewHouder) convertView.getTag();
        }
        Log.d("chengListView",bean.getList().size()+".");
        int yes;
        int Wrong;
        int Leak;
        String strYes=bean.getList().get(position).getCorrect_cnt();
        String strWrong=bean.getList().get(position).getError_cnt();
        String strLeak=bean.getList().get(position).getMissing_cnt();
        yes=Integer.parseInt(strYes);
        Wrong=Integer.parseInt(strWrong);
        Leak=Integer.parseInt(strLeak);
        int Total=yes+Wrong+Leak;
        houder.tvScollTime.setText(TimeFormat.DateFormat(bean.getList().get(position).getCreate_time()));
        houder.tvScollCount.setText(bean.getList().get(position).getUnit_name());
        houder.tvScollYes.setText("对:"+yes+"/"+Total+"");
        houder.tvScollWrong.setText("错:"+Wrong+"/"+Total);
        houder.tvScollWrong.setText("漏:"+Leak+"/"+Total);
        return convertView;
    }
    public class ViewHouder{
        TextView tvScollTime;
        TextView tvScollCount;//内容
        TextView tvScollYes;//对
        TextView tvScollWrong;//错
        TextView tvScollLeak;//漏
        TextView tvScollData;//用时
    }
}
